Executable computer code, sometimes called machine code, native code, or binary code, is computer instructions or software in the native format or language of a computer processor or system that is intended to run or execute the executable code. Object code is generally machine code that is the output of a compiler that has taken a higher-level source code language as input. In many situations where a change to a computer program in executable code format is required, a change will be made to the human readable source code, such as C or C++, from which the program's executable code originated, and then modified source code is compiled to produce a modified version of the executable code. In many situations, however, source code is not available or may have never existed, and hence modification of a program must be done by directly changing the executable code. For example, an end-user only rarely has access to source code, and in some situations, machine code is created directly without any source code ever existing. Direct modification of machine code (or binary code) such as this is called binary rewriting. Binary rewriting is done for many reasons such as improving or simply monitoring the security, performance, or reliability of a program. A binary executable program is often referred to as a “binary”.
A binary rewriter is a software tool that enables modifying binary code. It takes a binary code as input and produces an output binary code, which typically has the same functionality as input, but is enhanced in some way. These enhancements may serve a broad set of requirements such as better performance, better security features, additional instrumentation code for performance monitoring, to name a few. Binary rewriters include two main classes: static and dynamic.
Static binary rewriters take a static binary image present on the disk as input and create a new binary image that includes the required enhanced features. Since a static binary rewriter updates a binary code prior to its execution, it has a minimal impact on runtime performance and dynamic memory requirements of the binary code.
On the other hand, dynamic binary rewriters modify a binary code on the fly while it is executing. A dynamic binary rewriter acts as an execution layer between the binary code and the hardware that recompiles (translate) small sections of code at a time before running it on the hardware. This technique is popularly known as just-in-time compilation. The recompiled code in stored in a code cache to avoid the translation at each execution of a section of code.